package com.gdzn.netty.api.inner;

import cn.hutool.core.bean.BeanUtil;
import com.gdzn.common.core.domain.R;
import com.gdzn.netty.domain.DeviceCallParam;
import com.gdzn.netty.service.IRemoteCallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(value = "/call", tags = "下发指令")
@Tag(name = "下发指令")
@RestController
@RequestMapping("/inner/call" )
public class NettyCallInnerController {

	@Autowired
    private IRemoteCallService remoteCallService;

	/**
	 * 下发相关调用设备指令
	 * @param deviceCallParam
	 * @return
	 */
	@PostMapping("/callDevice")
    public R<Boolean> callDevice(@Parameter(name = "请求body-json对象") @RequestBody DeviceCallParam deviceCallParam) {
//		boolean flag = remoteCallService.callDevice(deviceCallParam);
//		boolean flag = remoteCallService.callDeviceByRedis(deviceCallParam);
		boolean flag = remoteCallService.callDeviceForMapByRedis(BeanUtil.beanToMap(deviceCallParam));
		return R.ok(flag);
    }

	/**
	 * 下发相关调用设备指令
	 * @param map
	 * @return
	 */
	@PostMapping("/map/callDevice")
	public R<Boolean> callDeviceForMap(@Parameter(name = "请求body-json对象") @RequestBody Map<String,Object> map) {
//		boolean flag = remoteCallService.callDeviceForMap(map);
		boolean flag = remoteCallService.callDeviceForMapByRedis(map);
		return R.ok(flag);
	}

}
